package com.ccq.controller;

import java.util.HashMap;
import java.util.Map;

import javax.jms.Topic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.ccq.domain.User;
import com.ccq.util.QueueList;

/*http://localhost:8161/admin/topics.jsp*/
@RestController
public class ActiveMqController {
	@Autowired
	private JmsMessagingTemplate jmsMessagingTemplate;
	@Autowired
	private Topic topic;

	@GetMapping("/mq1")
	public String mq() throws Exception {
		Map<String, String> map = new HashMap<>();
		map.put("key", "hi,activeMQ");
		jmsMessagingTemplate.convertAndSend(this.topic, JSON.toJSONString(map));
		return "messageSend Success";
	}

	@GetMapping(value = "/mq2")
	public String home2() throws Exception {
		for (int i = 0; i < 10; i++) {
			User u = new User("name", "age", i + "");
			jmsMessagingTemplate.convertAndSend(QueueList.BUSINESS2, JSON.toJSONString(u));
		}
		return "messageSend Success";
	}
}
